<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<jsp:include page="../../common/header.jsp"/>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<script>
jQuery(document).ready(function() {    
	
  
	
});

function delMenu(id,parentid){
	
	bootbox.dialog({
		message : "<spring:message code="confirm to delete the corresponding records"></spring:message>?",
		title : "<spring:message code="delete the menu"></spring:message>",
		buttons : {
			confirm : {
				label : '<spring:message code="sure to delete"></spring:message>',
				className : "btn red btn-ok",
				callback : function() {
					$.ajax({
						type : "GET",
						url : "<%=request.getContextPath()%>/sys/menu/delete?id="+id+"&parentid="+parentid,
						dataType : 'text',
						async : false,
						success : function(data) {
							if(data=="success"){
								//noty({layout: 'center',text: "删除用户成功！",type: 'success', timeout: 2000 });
								$("#list_form").attr("action","<%=request.getContextPath() %>/sys/menu/list");
								$("#list_form").submit();
							}else if(data=="HAS_LEAF"){
								noty({layout: 'center',text: "<spring:message code="failed to delete the menu, please first remove child nodes"></spring:message>！",type: 'error', timeout: 2000 });
							}else if(data=="HAS_PURVIEW"){
								noty({layout: 'center',text: "<spring:message code="delete menu fails, please delete the corresponding permissions"></spring:message>！",type: 'error', timeout: 2000 });
							}
						},
						error : function(data, status) {
							noty({layout: 'center',text: "<spring:message code="error"></spring:message>！",type: 'error', timeout: 2000 });
						}
					});
				}
			},
			cancel : {
				label : "<spring:message code="cancel"></spring:message>",
				className : "btn btn-danger"
			}
		}
	});
}




function toEditPage(id){
	$("#list_form").attr("action","<%=request.getContextPath() %>/sys/menu/form");
	$("#hiddenId").val(id);
	$("#list_form").submit();
}

function toSubMenuPage(id){
	$("#list_form").attr("action","<%=request.getContextPath() %>/sys/menu/list");
	$("#parentId").val(id);
	$("#list_form").submit();
}

function toListPage(pageIndex){
	$("#list_form").attr("action","<%=request.getContextPath() %>/sys/menu/list");
	$("#iDisplayStart").val(pageIndex);
	$("#list_form").submit();
}
//点击子菜单进入权限管理
function toSubPurviewPage(id){
	$("#list_form").attr("action","<%=request.getContextPath() %>/sys/menu-purview/list");
	$("#parentId").val(id);
	$("#list_form").submit();
}
</script>

</head>
<body class="page-header-fixed page-full-width">

	
		
		
		
		<form id="list_form" action="<%=request.getContextPath() %>/sys/menu/list">
		<input type="hidden" name="sorting_column_order" id="sorting_column_order" value="${list.orderBy }"/>
		<input type="hidden" name="sorting_asc_desc"  id="sorting_asc_desc" value="${list.sort}"/>
		<input type="hidden" name="parentid" id="parentId" value="${parentid}"></input>
		<input type="hidden" name="menParentId" id="menuparentId" value="${parentid}"></input>
		<input type="hidden" name="id" id="hiddenId"></input>
		<input type="hidden" name="iDisplayStart" id="iDisplayStart"/>
		<div class="page-content">


			<!-- BEGIN PAGE CONTAINER-->

			<div class="container-fluid">

				<p></p>

				<div class="row-fluid">
							<!-- BEGIN EXAMPLE TABLE PORTLET-->

						

							<c:if test="${parentid!=null }">
							<div class="portlet-title">

								<div class="caption"><i class="icon-globe"></i>${menu.sname}-子菜单列表
									&nbsp;&nbsp;
									<a href="#" onclick="toSubMenuPage(${menu.parentid});" class="btn mini gray" >

										<spring:message
													code="btn.common.back"></spring:message>

										</a>
									
								</div>
							</div> 
							</c:if>

							<div class="portlet-body">

								<div class="clearfix">

									<p class="pull-left">
										
									
										
										<a href="#" onclick="toEditPage(null);" class="btn blue" >

									<spring:message code="btn.common.add.menu"></spring:message> <i class="icon-plus"></i>

										</a>
									</p>

									

								</div>
								

								<table class="table table-striped table-bordered table-hover" id="user_grid">

									<thead>

										<tr>
											<th><spring:message
									code="menu name en"></spring:message></th>
											<th><spring:message
									code="menu name cn"></spring:message></th>
											<th><spring:message
									code="menu path"></spring:message></th>
											<!--<th>备注</th>-->
											<th><spring:message
									code="order id"></spring:message></th>
											<th><spring:message code="operation"></spring:message></th>
										</tr>

									</thead>
									<tbody>
										<c:forEach items="${list.resultList}" var="item" varStatus="status">
										
									
										<tr class="odd gradeX">

											<td>${item.sname_en }</td>
											<td>${item.sname }</td>
											<td>${item.smenupath }</td>

											<!-- <td>${item.sremark }</td> -->

											<td>${item.isort }</td>
											
											<td>
												<a  href="#" onclick="toEditPage(${item.sysMenuId});" class="btn mini blue"><spring:message
																code="btn.common.edit"></spring:message></a>
												<c:if test="${item.bisleaf==1}">
													<a onclick="delMenu(${item.sysMenuId},${item.parentid==null?-1:item.parentid});" href="#"  class="btn mini red" ><spring:message
																code="btn.common.delete"></spring:message></a>
												</c:if>
												<a onclick="toSubMenuPage(${item.sysMenuId})" href="#"  class="btn mini blue" ><spring:message
																code="sub menu"></spring:message></a>
												<c:if test="${item.bisleaf==1}">
												<a onclick="toSubPurviewPage(${item.sysMenuId})" href="#"  class="btn mini blue" >
												<spring:message
																code="purview manage"></spring:message></a>
											   </c:if>
											</td>

										</tr>
										</c:forEach>
									</tbody>
									
								</table>
								<!-- 分页 -->
								<c:if test="${list.totalPages>1}">
									<div class="pagination" style="float:right">
										<ul>
											<li><a href="javascript:void();"><spring:message
														code="total"></spring:message>：${list.totalRows}</a></li>
											<li <c:if test="${list.currentPage==1}">class="disabled"</c:if>>
												<c:if test="${list.currentPage>1}">
													<a href="javascript:toListPage(${list.currentPage-1});"><spring:message
														code="previous page"></spring:message></a>
												</c:if>
												<c:if test="${list.currentPage==1}">
													<a href="#"><spring:message
														code="previous page"></spring:message></a>
												</c:if>
											</li>
											<c:forEach begin="1" end="${list.totalPages}" var="item">
											<c:if test="${item < 4 || item==list.currentPage || item==list.currentPage+1 || item==list.currentPage+2 || item + 3 > list.totalPages }">
											<li <c:if test="${list.currentPage==item }">class="active"</c:if>><a href="javascript:toListPage(${item});">${item}</a></li></c:if>
											</c:forEach>
											<li <c:if test="${list.currentPage==list.totalPages}">class="disabled"</c:if>>
												<c:if test="${list.currentPage==list.totalPages}">
													<a href="#"><spring:message
														code="next page"></spring:message> </a>
												</c:if>
												<c:if test="${list.currentPage!=list.totalPages}">
													<a href="javascript:toListPage(${list.currentPage+1})"><spring:message
														code="next page"></spring:message> </a>
												</c:if>
											</li>
										</ul>
									</div>
								</c:if>
							</div>

						  

						</div>
			</div>


		</div>
		
		</form>
		

	


</body>